package com.netty.demo.thrift;

import com.thrift.generated.Person;
import com.thrift.generated.PersonService;
import org.apache.thrift.protocol.TCompactProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TFramedTransport;
import org.apache.thrift.transport.TSocket;

public class ThriftClient {

    public static void main(String[] args){
        TFramedTransport tFramedTransport = new TFramedTransport(new TSocket("localhost", 8899), 600);

        TCompactProtocol tCompactProtocol = new TCompactProtocol(tFramedTransport);

        PersonService.Client client = new PersonService.Client(tCompactProtocol);

        try {
            tFramedTransport.open();

            Person agan = client.getPersonByUsername("agan");
            System.out.println(agan.getAge());
            System.out.println(agan.getUsername());
            System.out.println(agan.isMarried());

            Person person = new Person();
            person.setMarried(true);
            person.setUsername("lisi");
            person.setAge(21);
            client.savePerson(person);




        } catch (Exception e) {

        }finally {
            tFramedTransport.close();
        }

    }
}
